From 8e42b4e0aa45f473a365e07540a37ba53c7ddd1c Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Tue, 17 Aug 2004 22:53:36 +0000 Subject: [PATCH] Added path distance options to xcsv --- csv_util.c | 40 +++++++++++++++++++++++-- internal_styles.c | 3 +- reference/dusky.gnuplot | 65 +++++++++++++++++++++++++++++++++++++++++ reference/dusky.trk | 63 +++++++++++++++++++++++++++++++++++++++ reference/gnuplot.style | 26 +++++++++++++++++ style/README.style | 16 ++++++++-- style/tabsep.style | 3 +- testo | 8 +++++ 8 files changed, 218 insertions(+), 6 deletions(-) create mode 100644 reference/dusky.gnuplot create mode 100755 reference/dusky.trk create mode 100644 reference/gnuplot.style diff --git a/csv_util.c b/csv_util.c index 861b8f267..20899f080 100644 --- a/csv_util.c +++ b/csv_util.c @@ -22,6 +22,7 @@ #include #include "defs.h" #include "csv_util.h" +#include "grtcirc.h" #define MYNAME "CSV_UTIL" @@ -38,6 +39,10 @@ extern char *xcsv_urlbase; extern char *prefer_shortnames; +static double pathdist = 0; +static double oldlon = 999; +static double oldlat = 999; + static int waypt_out_count; /*********************************************************************/ @@ -695,6 +700,12 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp) } else if (strcmp(fmp->key, "GEOCACHE_CONTAINER") == 0) { wpt->gc_data.container = gs_mkcont(s); + } else + if ( strcmp( fmp->key, "PATH_DISTANCE_MILES") == 0) { + /* Ignored on input */ + } else + if ( strcmp( fmp->key, "PATH_DISTANCE_KM") == 0 ) { + /* Ignored on input */ } else { warning( MYNAME ": Unknown style directive: %s\n", fmp->key); } @@ -776,6 +787,14 @@ xcsv_data_read(void) } while (!feof(xcsv_file.xcsvfp)); } +static void +xcsv_resetpathlen() +{ + pathdist = 0; + oldlat = 999; + oldlon = 999; +} + /*****************************************************************************/ /* xcsv_waypt_pr() - write output file, handling output conversions */ /* (the output meat) */ @@ -791,6 +810,13 @@ xcsv_waypt_pr(const waypoint *wpt) int i; field_map_t *fmp; queue *elem, *tmp; + + if ( oldlon < 900 ) { + pathdist += tomiles(gcdist(oldlat*M_PI/180,oldlon*M_PI/180, + wpt->latitude*M_PI/180,wpt->longitude*M_PI/180)); + } + oldlon = wpt->longitude; + oldlat = wpt->latitude; if (strcmp(xcsv_file.field_delimiter, "\\w") == 0) write_delimiter = " "; @@ -980,6 +1006,16 @@ xcsv_waypt_pr(const waypoint *wpt) sprintf(buff, fmp->printfc, wpt->altitude); } else + + /* DISTANCE CONVERSIONS**********************************************/ + if (strcmp(fmp->key, "PATH_DISTANCE_MILES") == 0) { + /* path (route/track) distance in miles */ + sprintf( buff, fmp->printfc, pathdist ); + } else + if (strcmp(fmp->key, "PATH_DISTANCE_KM") == 0) { + /* path (route/track) distance in */ + sprintf( buff, fmp->printfc, pathdist * 5280*12*2.54/100/1000 ); + } else /* TIME CONVERSIONS**************************************************/ if (strcmp(fmp->key, "EXCEL_TIME") == 0) { @@ -1063,8 +1099,8 @@ xcsv_data_write(void) } waypt_disp_all(xcsv_waypt_pr); - route_disp_all(xcsv_noop,xcsv_noop,xcsv_waypt_pr); - track_disp_all(xcsv_noop,xcsv_noop,xcsv_waypt_pr); + route_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr); + track_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr); /* output epilogue lines, if any. */ QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) { diff --git a/internal_styles.c b/internal_styles.c index ab5bc6143..3b31cde74 100644 --- a/internal_styles.c +++ b/internal_styles.c @@ -489,7 +489,8 @@ static char tabsep[] = "IFIELD GEOCACHE_TERR,\"\",\"%3.1f\"\n" "IFIELD GEOCACHE_CONTAINER,\"\",\"%s\"\n" "IFIELD GEOCACHE_TYPE,\"\",\"%s\"\n" - +"IFIELD PATH_DISTANCE_MILES,\"\",\"%f\"\n" +"IFIELD PATH_DISTANCE_KM, \"\", \"%f\"\n" ; static char xmap[] = "# gpsbabel XCSV style file\n" diff --git a/reference/dusky.gnuplot b/reference/dusky.gnuplot new file mode 100644 index 000000000..f02feb7b0 --- /dev/null +++ b/reference/dusky.gnuplot @@ -0,0 +1,65 @@ +plot "-" with lines +0.000000 623.352000 +2.971829 711.933600 +3.285049 715.214400 +3.616714 715.214400 +5.524296 705.372000 +9.412893 659.440800 +23.470340 606.948000 +25.016243 610.228800 +30.981982 623.352000 +32.467702 616.790400 +34.341455 629.913600 +39.151887 639.756000 +40.148722 643.036800 +43.855057 639.756000 +45.197995 639.756000 +50.241520 643.036800 +50.751146 613.509600 +52.418822 652.879200 +59.685934 662.721600 +61.251560 698.810400 +71.654560 738.180000 +72.528252 764.426400 +87.945745 721.776000 +88.792305 725.056800 +91.616705 764.426400 +99.657820 902.220000 +99.800297 905.500800 +99.971950 905.500800 +100.189154 902.220000 +100.572379 882.535200 +102.010350 882.535200 +102.804092 875.973600 +103.080392 872.692800 +107.397520 921.904800 +107.921923 915.343200 +111.807511 977.678400 +112.360714 974.397600 +113.798888 1003.924800 +115.624455 967.836000 +119.337749 1082.664000 +120.301609 1040.013600 +122.631756 1030.171200 +125.020430 1056.417600 +125.198791 1089.225600 +127.787125 1076.102400 +129.889131 997.363200 +130.326239 974.397600 +130.940014 971.116800 +131.414289 1020.328800 +142.699566 935.028000 +147.684227 905.500800 +154.362718 902.220000 +155.048874 889.096800 +155.659180 872.692800 +156.187932 846.446400 +156.833988 869.412000 +157.381754 875.973600 +159.890999 846.446400 +159.999868 856.288800 +163.196258 866.131200 +164.732014 869.412000 +164.932308 859.569600 +165.120360 849.727200 +e diff --git a/reference/dusky.trk b/reference/dusky.trk new file mode 100755 index 000000000..26d099c65 --- /dev/null +++ b/reference/dusky.trk @@ -0,0 +1,63 @@ +$PMGNTRK,4122.991,N,08244.336,W,00190,M,030730.19,A,,170804*67 +$PMGNTRK,4120.566,N,08245.501,W,00217,M,031055.19,A,,170804*6B +$PMGNTRK,4120.585,N,08245.862,W,00218,M,031137.19,A,,170804*64 +$PMGNTRK,4120.513,N,08246.233,W,00218,M,031200.20,A,,170804*6B +$PMGNTRK,4120.853,N,08248.390,W,00215,M,031334.19,A,,170804*65 +$PMGNTRK,4121.287,N,08252.846,W,00201,M,031645.20,A,,170804*60 +$PMGNTRK,4124.603,N,08308.485,W,00185,M,032817.22,A,,170804*67 +$PMGNTRK,4125.265,N,08310.040,W,00186,M,032933.22,A,,170804*62 +$PMGNTRK,4127.211,N,08316.436,W,00190,M,033426.23,A,,170804*6E +$PMGNTRK,4127.905,N,08317.885,W,00188,M,033539.23,A,,170804*63 +$PMGNTRK,4128.434,N,08319.936,W,00192,M,033711.23,A,,170804*67 +$PMGNTRK,4130.583,N,08324.711,W,00195,M,034107.24,A,,170804*60 +$PMGNTRK,4130.816,N,08325.823,W,00196,M,034156.24,A,,170804*69 +$PMGNTRK,4132.270,N,08329.653,W,00195,M,034458.24,A,,170804*6C +$PMGNTRK,4132.495,N,08331.180,W,00195,M,034604.24,A,,170804*6A +$PMGNTRK,4134.715,N,08336.218,W,00196,M,035012.25,A,,170804*60 +$PMGNTRK,4134.982,N,08336.689,W,00187,M,035037.26,A,,170804*68 +$PMGNTRK,4135.439,N,08338.524,W,00199,M,035159.25,A,,170804*6B +$PMGNTRK,4135.725,N,08346.944,W,00202,M,035757.27,A,,170804*6D +$PMGNTRK,4136.163,N,08348.663,W,00213,M,035914.28,A,,170804*68 +$PMGNTRK,4135.898,N,08400.725,W,00225,M,040751.28,A,,170804*66 +$PMGNTRK,4135.563,N,08401.634,W,00233,M,040834.28,A,,170804*64 +$PMGNTRK,4135.463,N,08419.515,W,00220,M,042119.30,A,,170804*63 +$PMGNTRK,4135.256,N,08420.457,W,00221,M,042200.30,A,,170804*64 +$PMGNTRK,4136.223,N,08423.467,W,00233,M,042419.30,A,,170804*68 +$PMGNTRK,4136.841,N,08432.759,W,00275,M,043059.32,A,,170804*69 +$PMGNTRK,4136.921,N,08432.885,W,00276,M,043110.32,A,,170804*6F +$PMGNTRK,4136.784,N,08432.963,W,00276,M,043129.32,A,,170804*6D +$PMGNTRK,4136.784,N,08433.215,W,00275,M,043213.32,A,,170804*6F +$PMGNTRK,4137.115,N,08433.174,W,00269,M,043246.33,A,,170804*68 +$PMGNTRK,4138.362,N,08433.212,W,00269,M,043425.32,A,,170804*64 +$PMGNTRK,4138.607,N,08434.073,W,00267,M,043521.32,A,,170804*6B +$PMGNTRK,4138.623,N,08434.393,W,00266,M,043541.33,A,,170804*66 +$PMGNTRK,4138.600,N,08439.404,W,00281,M,044011.33,A,,170804*6D +$PMGNTRK,4138.462,N,08439.984,W,00279,M,044042.34,A,,170804*68 +$PMGNTRK,4138.239,N,08444.484,W,00298,M,044508.34,A,,170804*63 +$PMGNTRK,4138.120,N,08445.106,W,00297,M,044555.33,A,,170804*66 +$PMGNTRK,4138.074,N,08446.774,W,00306,M,044739.34,A,,170804*60 +$PMGNTRK,4137.843,N,08448.870,W,00295,M,044931.35,A,,170804*6A +$PMGNTRK,4137.764,N,08453.178,W,00330,M,045258.34,A,,170804*61 +$PMGNTRK,4137.955,N,08454.267,W,00317,M,045357.35,A,,170804*6D +$PMGNTRK,4137.894,N,08456.970,W,00314,M,045620.36,A,,170804*6B +$PMGNTRK,4138.096,N,08459.729,W,00322,M,045913.35,A,,170804*6A +$PMGNTRK,4138.095,N,08459.936,W,00332,M,045934.37,A,,170804*6F +$PMGNTRK,4138.097,N,08502.940,W,00328,M,050333.36,A,,170804*60 +$PMGNTRK,4136.276,N,08502.817,W,00304,M,050534.38,A,,170804*61 +$PMGNTRK,4135.918,N,08502.984,W,00297,M,050557.38,A,,170804*64 +$PMGNTRK,4135.492,N,08503.411,W,00296,M,050629.37,A,,170804*6F +$PMGNTRK,4135.093,N,08503.545,W,00311,M,050654.38,A,,170804*61 +$PMGNTRK,4125.307,N,08503.218,W,00285,M,051640.39,A,,170804*68 +$PMGNTRK,4121.266,N,08505.268,W,00276,M,052059.39,A,,170804*6A +$PMGNTRK,4115.473,N,08505.236,W,00275,M,052641.40,A,,170804*66 +$PMGNTRK,4114.916,N,08505.515,W,00271,M,052716.41,A,,170804*69 +$PMGNTRK,4114.388,N,08505.566,W,00266,M,052747.41,A,,170804*62 +$PMGNTRK,4113.962,N,08505.792,W,00258,M,052814.41,A,,170804*66 +$PMGNTRK,4113.476,N,08506.163,W,00265,M,052847.41,A,,170804*6D +$PMGNTRK,4113.012,N,08506.299,W,00267,M,052915.40,A,,170804*68 +$PMGNTRK,4110.836,N,08506.233,W,00258,M,053124.41,A,,170804*63 +$PMGNTRK,4110.746,N,08506.271,W,00261,M,053135.41,A,,170804*67 +$PMGNTRK,4110.661,N,08509.953,W,00264,M,053607.41,A,,170804*64 +$PMGNTRK,4109.329,N,08509.927,W,00265,M,053802.42,A,,170804*6F +$PMGNTRK,4109.315,N,08509.697,W,00262,M,053828.41,A,,170804*68 +$PMGNTRK,4109.278,N,08509.486,W,00259,M,053858.41,A,,170804*6F diff --git a/reference/gnuplot.style b/reference/gnuplot.style new file mode 100644 index 000000000..980b91fb0 --- /dev/null +++ b/reference/gnuplot.style @@ -0,0 +1,26 @@ +# gpsbabel XCSV style file +# +# Format: GnuPlot output for track profiles +# Author: Ron Parker +# Date: 17 Aug 2004 +# +# + +DESCRIPTION Gnuplot track profile + +# FILE LAYOUT DEFINITIIONS: +# +FIELD_DELIMITER TAB +RECORD_DELIMITER NEWLINE +BADCHARS TAB + +# +# INDIVIDUAL DATA FIELDS: +# +PROLOGUE plot "-" with lines + +IFIELD PATH_DISTANCE_MILES, "", "%lf" +IFIELD ALT_FEET, "", "%f" + +EPILOGUE e + diff --git a/style/README.style b/style/README.style index 78971a04c..e8bdb047e 100644 --- a/style/README.style +++ b/style/README.style @@ -355,8 +355,20 @@ The fields used by the XCSV parser are as follows: example: GEOCACHE_TYPE,"","%s" - - + o PATH_DISTANCE_MILES + PATH_DISTANCE_MILES outputs the total length of the route or track from + the start point to the current point, in miles. This and the altitude + could be used to create an elevation profile. PATH_DISTANCE_MILES is + a DOUBLE PRECISION FLOAT. + PATH_DISTANCE_MILES is not valid as an input field. + PATH_DISTANCE_MILES is only meaningful if the data comes from a track + or a route; waypoint data will generate essentially meaningless output. + + example: PATH_DISTANCE_MILES,"","%f" + + o PATH_DISTANCE_KM + PATH_DISTANCE_KM is like PATH_DISTANCE_MILES except it outputs the + length in kilometers. EXAMPLES: -------- diff --git a/style/tabsep.style b/style/tabsep.style index 5967d07f4..7176e813e 100644 --- a/style/tabsep.style +++ b/style/tabsep.style @@ -49,4 +49,5 @@ IFIELD GEOCACHE_DIFF,"","%3.1f" IFIELD GEOCACHE_TERR,"","%3.1f" IFIELD GEOCACHE_CONTAINER,"","%s" IFIELD GEOCACHE_TYPE,"","%s" - +IFIELD PATH_DISTANCE_MILES,"","%f" +IFIELD PATH_DISTANCE_KM, "", "%f" diff --git a/testo b/testo index ded25c418..07a0eff1c 100755 --- a/testo +++ b/testo @@ -533,4 +533,12 @@ rm -f ${TMPDIR}/humanwrite.out ${PNAME} -i xcsv,style=reference/humanread.style -f reference/human.in -o xcsv,style=reference/humanwrite.style -F ${TMPDIR}/humanwrite.out compare ${TMPDIR}/humanwrite.out reference/humanwrite.out +# +# XCSV "path distance" test +# +rm -f ${TMPDIR}/pathdist.out +${PNAME} -i magellan -f reference/dusky.trk -o xcsv,style=reference/gnuplot.style -F ${TMPDIR}/pathdist.out +compare ${TMPDIR}/pathdist.out reference/dusky.gnuplot + + exit 0 -- 2.30.2